<?php
/**
 * centro actions.
 *
 * @package    espazio
 * @subpackage centro
 * @author     Your name here
 * @version    SVN: $Id: actions.class.php 12474 2008-10-31 10:41:27Z fabien $
 */
class centroActions extends sfActions
{
  public function executeIndex(sfWebRequest $request)
  {
    //$this->centro_list = CentroPeer::doSelect(new Criteria
     $this->centro_list = CentroPeer::doSelect(new Criteria());
    
    
 }

 public function executeShow(sfWebRequest $request)
  {
    // Recogo los parametros que se envian en la URL
    // familia a la que pertenece
     $this->familia=$request->getParameter('familia');
     // Titulacion (estudio) de la que quiero mostrar todos los centros
     $this->estudio=$request->getParameter('estudio');

    // Listado de todas las titulaciones de la subfamilia que se pasa como parametro y que lo guardo
    // en la variabla familia
    // Busco el padre de la familia
    $c1 = new Criteria();
    $c1 -> add(FamiliaPeer::NOMBRE,$this->familia);
    $this->familia_list_id = FamiliaPeer::doSelect($c1);

    $id= $this->familia_list_id[0]->getId();
   
    $c2 = new Criteria();
    $c2 -> add(EstudioPeer::FAMILIA_ID,$id);
    $this->familia_list= EstudioPeer::doSelect($c2);
      
    //  $this->forward404Unless($this->familia);

   //Busqueda de todos los centros donde se imparte una titulacion (estudio)
    $c = new Criteria();
    $c -> add(CentroEstudioPeer::ESTUDIO_ID,$this->estudio);
    $this->centro_list = CentroEstudioPeer::doSelectJoinEstudio($c);
    // Estudio

 }

  public function executeNew(sfWebRequest $request)
  {
    $this->form = new CentroForm();
  }

  public function executeCreate(sfWebRequest $request)
  {
    $this->forward404Unless($request->isMethod('post'));

    $this->form = new CentroForm();

    $this->processForm($request, $this->form);

    $this->setTemplate('new');
  }

  public function executeEdit(sfWebRequest $request)
  {
    $this->forward404Unless($centro = CentroPeer::retrieveByPk($request->getParameter('id')), sprintf('Object centro does not exist (%s).', $request->getParameter('id')));
    $this->form = new CentroForm($centro);
  }

  public function executeUpdate(sfWebRequest $request)
  {
    $this->forward404Unless($request->isMethod('post') || $request->isMethod('put'));
    $this->forward404Unless($centro = CentroPeer::retrieveByPk($request->getParameter('id')), sprintf('Object centro does not exist (%s).', $request->getParameter('id')));
    $this->form = new CentroForm($centro);

    $this->processForm($request, $this->form);

    $this->setTemplate('edit');
  }

  public function executeDelete(sfWebRequest $request)
  {
    $request->checkCSRFProtection();

    $this->forward404Unless($centro = CentroPeer::retrieveByPk($request->getParameter('id')), sprintf('Object centro does not exist (%s).', $request->getParameter('id')));
    $centro->delete();

    $this->redirect('centro/index');
  }

  protected function processForm(sfWebRequest $request, sfForm $form)
  {
    $form->bind($request->getParameter($form->getName()), $request->getFiles($form->getName()));
    if ($form->isValid())
    {
      $centro = $form->save();

      $this->redirect('centro/edit?id='.$centro->getId());
    }
  }
}
